<?php

/**
 * 作者：lucas
 * 链接：
 * 邮箱：dissipator_520@qq.com
 */

/**
 * Packg Mod
 *
 * @author lucas
 */
class FhViewModel extends Model {

    // public $_validate = array(
    //     array('text', 'require', '必须填写名称'),
    //     array('href,issort', 'checkHref', '必须填写链接地址', 1, 'callback')
    // );
    // public $_auto = array(
    //     array('href', 'lower', self::MODEL_BOTH, 'callback')
    // );

    public function getFYdata() {

            $sql = "select '年数据' xname ,year(fhdate) sname,SUM(QTY)/10000 data 
                   from " . C('DB_PREFIX') . "fhqr  where year(fhdate)>=year(now())-2
                   group by year(fhdate),1";
            return $this->query($sql);
            // Log::write($sql);

    }

        public function getMCdata() {

            $sql = "select year(fhdate) stack, FHDATE xname ,PACKAGE sname,SUM(QTY)/10000 data 
                   from " . C('DB_PREFIX') . "fhqr  where year(fhdate)=year(now()) and MONTH(FHDATE)=MONTH(now())
                   group by year(fhdate),FHDATE,PACKAGE";
            return $this->query($sql);
            // Log::write($sql);

    }

    public function getECdata() {

            $sql = "select year(fhdate) stack, MONTH(FHDATE) xname ,PACKAGE sname,SUM(QTY)/10000 data 
                   from " . C('DB_PREFIX') . "fhqr  where year(fhdate)=year(now())
                   group by year(fhdate),MONTH(FHDATE),PACKAGE";
            return $this->query($sql);
            // echo $sql;

    }

    public function getTCdata() {

            $sql = "select year(fhdate) stack,MONTH(FHDATE) xname ,'Total' sname,SUM(QTY)/10000 data 
                   from " . C('DB_PREFIX') . "fhqr  where year(fhdate)=year(now())
                   group by year(fhdate),MONTH(FHDATE)";
            return $this->query($sql);
            // Log::write($sql);

    }

    public function getECFdata() {

            $sql = "select year(fhdate) sname, MONTH(FHDATE) xname ,SUM(QTY)/10000 data 
                   from " . C('DB_PREFIX') . "fhqr  where fhdate>0
                   group by year(fhdate),MONTH(FHDATE)";
            return $this->query($sql);
            // Log::write($sql);

    }

    public function getECpdata() {

            $sql = "select year(fhdate) sname,MONTH(fhdate) xname,count(boxno) data from 
                 (select fhdate,boxno from wip_packg where YEAR(FHDATE)>=2012 group by fhdate,addre,boxno) a
                 group by MONTH(fhdate),year(fhdate)";
            return $this->query($sql);
            // Log::write($sql);

    }

    public function getFhqrDataByUid() {
        if (!empty($uid)) {
            $sql = "select * from " . C('DB_PREFIX') . "fhqr  order by ID desc ";
            return $this->query($sql);
            // Log::write($sql);
        }
        return null;
    }

}

?>

